Skip to content

fix(base): 上方的行量到新高度时,屏幕上的行保持不动 - #86

Closed
xiaoyumuxi wants to merge 1 commit into
mainfrom
fix/list-scroll-anchor
Closed

xiaoyumuxi wants to merge 1 commit into
mainfrom
fix/list-scroll-anchor

Conversation

@xiaoyumuxi

Copy link
Copy Markdown

问题

List 对没量过的行按已量行的平均高度估算位置。往上量到新行,或者平均值随之变化时,视口里每一行的计算起点都会跟着移动,但滚动偏移没有补偿,所以屏幕上的内容会跳。

  • 行高差别大的长列表(例如对话记录:短的提问、工具行,加上很长的回复)从末尾往上读时,滚一格滚轮,内容可能跳出整个视口。
  • 快速甩动跳过了一些没排版过的行之后,再滚动也会一抖一抖的。

复现(600 行,30/30/300 交替,480 高视口,从末尾每次滚轮 24):修复前,追踪的一行多次在一次滚轮后直接离开屏幕,最大偏差 88 px 以上;修复后每一步都移动 24 ± 1 px。

修复(base/list.go)

  • 每次排版记住视口顶部那一行(锚点),以及为它选定偏移时它应该在的位置。
  • 下一次排版先按这一行在内容坐标里移动了多少来移动偏移(keepAnchor)。两次排版之间滚轮和按键带来的位移保持不变。
  • 本帧补齐上方预渲染行(overscan)时量到的高度和估算不同,锚点已经偏了:沿用 Page 已有的重画机制(p.retry),这一帧带着补偿后的偏移重画一次,不把错位显示出来。
  • 以下情况不补偿:有 ScrollTo 请求、跟随末尾(Follow)、正在拖动滚动条。

Tree 用同一个 ListArea,一起受益。

测试

  • 新增 ui/list_anchor_test.go:TestListKeepsTheRowsOnScreenAsRowsAboveAreMeasured。撤掉修复后失败,加上后通过。
  • go test ./base/ ./ui/ 全部通过。components、internal/gallery、tools/docs、tools/visualparity 的失败在 fork main 上原本就有(dock 文档目录、OTP 示例、对照像素),和本改动无关。
  • Lithe 里固定到本提交后,工作台测试和 Agent 无头截图测试通过。工作台滚动基准每帧 0.37~0.58 ms,和修复前持平。

A List places rows it has not measured by the average height of those it
has. Measuring a row above the viewport, or the estimate changing with it,
moved where every row on screen was computed to start, so reading a long
list of uneven rows upward from its end (or after a fling skipped rows)
made the rows jump, sometimes by more than the viewport.

The list now keeps the row at the top of the viewport where the offset was
chosen for it: the next paint moves the offset by as much as that row moved
in content space, and a paint whose overscan rows measured differently is
painted again with the offset kept. Requests to scroll, following the end
and scrollbar drags are left as they were.
@1lck

1lck commented Dec 2, 2026

Copy link
Copy Markdown

已被上游 vivaui#532 (dd048cd) 取代,并在 #89 同步进 fork main。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants